package com.mornd.gulimall.coupon.feign;

import com.mornd.gulimall.apis.coupon.ICouponClient;
import com.mornd.gulimall.apis.coupon.to.BoundsTo;
import com.mornd.gulimall.apis.coupon.to.SeckillSessionTo;
import com.mornd.gulimall.apis.coupon.to.SkuReductionTo;
import com.mornd.gulimall.common.core.result.AjaxResult;
import com.mornd.gulimall.common.core.result.R;
import com.mornd.gulimall.coupon.entity.SpuBounds;
import com.mornd.gulimall.coupon.service.ISeckillSessionService;
import com.mornd.gulimall.coupon.service.ISkuFullReductionService;
import com.mornd.gulimall.coupon.service.ISpuBoundsService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

import static com.mornd.gulimall.common.core.result.AjaxResult.success;


/**
 * @author: mornd
 * @dateTime: 2023/7/23 - 10:40
 */

@RestController
public class CouponClient implements ICouponClient {
    @Resource
    private ISpuBoundsService spuBoundsService;
    @Resource
    private ISkuFullReductionService fullReductionService;
    @Resource
    private ISeckillSessionService seckillSessionService;

    @Override
    public AjaxResult saveBounds(BoundsTo boundsTo) {
        SpuBounds spuBounds = new SpuBounds();
        BeanUtils.copyProperties(boundsTo, spuBounds);
        spuBoundsService.save(spuBounds);
        return success(spuBounds.getId());
    }

    @Override
    public AjaxResult saveSkuReductions(List<SkuReductionTo> skuReductionTo) {
        fullReductionService.saveSkuReductions(skuReductionTo);
        return success();
    }

    @Override
    public R<List<SeckillSessionTo>> latestDaysSeckillSessions(int day) {
        List<SeckillSessionTo> list = seckillSessionService.latestDaysSeckillSessions(day);
        return R.ok(list);
    }
}
